<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Button;
use addons\BuilderPlus\components\Column;
use addons\BuilderPlus\components\Search;
use addons\BuilderPlus\facade\Table;
use app\common\model\Assets;

class Remit extends Base
{
    public function getOptions(): array
    {
        return [
            'pk' => 'id',
            'model' => \app\common\model\Remit::class,
            'with' => ['user'],
            'append' => ['status_name'],
            'just' => false,
            'fast' => [
                'edit' => 'remit/edit',
                'save' => '_save',
                'batchPass' => 'batchPass',
                'batchReject' => 'batchReject'
            ]
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->addColumns([
                ['id', 'ID', fn(Column $col) => $col->width(80)],
                ['uid', '相关会员', fn(Column $col) => $col->templet('#_userTpl')->minWidth(240)],
                ['account', '充值账户'],
                ['pay_way', '充值方式'],
                ['amount', '充值金额'],
                ['images', '充值凭证', fn(Column $col) => $col->lazyImage()->width(100)],
                ['create_time', '申请时间', fn(Column $col) => $col->width(150)],
                ['admin_name', '审核人'],
                ['examine_time', '审核时间', fn(Column $col) => $col->width(150)],
                ['status_name', '状态', fn(Column $col) => $col->fixed('right')]
            ])
            ->addTopButtons([
                'batchPass' => fn(Button $btn) => $btn->title('批量通过')
                    ->icon('layui-icon-util')
                    ->url(url('batchPass')->build())
                    ->event('batch'),
                'batchReject' => fn(Button $btn) => $btn->title('批量驳回')
                    ->icon('layui-icon-util')
                    ->class('danger')
                    ->url(url('batchReject')->build())
                    ->formType(2)
                    ->placeholder('请填写驳回原因')
                    ->event('prompt')
            ])
            ->addRightButtons([
                'edit' => fn(Button $btn) => $btn->title("{{ d.status == 1 ? '审核' : '查看' }}")
                    ->class("{{ d.status == 1 ? 'danger' : 'normal' }}")
            ], 100)
            ->addSearch([
                ['create_time', '申请时间', fn(Search $search) => $search->type('date')],
                ['uid', '会员编号/昵称/手机号', fn(Search $search) => $search
                    ->relation('\app\common\model\User', 'code|nickname|mobile,id')
                    ->condition('Like')],
                ['account', '账户类型', fn(Search $search) => $search->type('select')
                    ->optionValue(Assets::getFields(3))],
                ['status', '状态', fn(Search $search) => $search->type('select')
                    ->optionValue(getExamineStatus())]
            ])
            ->enableExport()
            ->fetch();
    }
}